package com.badlogic.agdwikisamples.utils;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

/**
 * Basic OpenGL ES Activity, just derrive from it and implement the abstract methods appropriately.
 * 
 * @author mzechner
 *
 */
public abstract class GLActivity extends Activity implements GLSurfaceView.Renderer
{
	GLSurfaceView view;
	int width = 0;
	int height = 0;
	
	public void onCreate( Bundle bundle )
	{
		super.onCreate( bundle );
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    	view = new GLSurfaceView( this );
    	view.setRenderer( this );
    	
    	setContentView( view );
	}

	@Override
	public void onDrawFrame(GL10 gl) 
	{
		render( gl, width, height );
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) 
	{
		this.width = width;
		this.height = height;
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) 
	{
		
	}
	
	protected void onPause( )
	{
		super.onPause( );
		view.onPause();
		destroy( );
	}
	
	protected void onResume( )
	{
		super.onResume( );
		view.onResume( );
		init( );
	}
	
	public abstract void init( );
	public abstract void render( GL10 gl, int width, int height );
	public abstract void destroy( );
}
